<template>
  <div class="login-main">
    <div class="form">
      <div class="title">登录到可视化平台</div>
      <div>
        <span>账户名：</span><input type="text" placeholder="请输入账号" v-model="username">
      </div>
      <div>
        <span>密码：</span><input type="password" placeholder="请输入密码" v-model="password">
      </div>
      <div class="btn" @click="login">登录</div>
    </div>
  </div>
</template>

<script>
import { Login } from '../api/main'

export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login() {
      Login({
        username: this.username,
        password: this.password
      }).then(res => {
        if (res.data.success) {
          this.$message.success('登陆成功！')
          setTimeout(() => {
            this.$router.push('/')
          }, 1000)
          // 本地登录态 没有登出，要手动去清除
          localStorage.setItem('isLogin', true)
        } else {
          this.$message.error(res.data.message)
        }
      })
    }
  }
}
</script>

<style>
.login-main {
  background-image: url("../assets/pageBg.png");
  width: 100%;
  height: 100%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  /* background-color: #fff; */
}

.form {
  display: flex;
  flex-direction: column;
  background-color: #fff;
  padding: 30px;
  border-radius: 15px;
  color: black;
}

.title {
  text-align: center;
  margin-bottom: 30px;
}

.btn {
  background-color: #409EFF;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
}

input {
  outline: none;
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid #E4E7ED;
  border-radius: 5px;
}

span {
  display: inline-block;
  width: 80px;
}
</style>